<!--
 * @Description: 任务资产充值记录弹窗
 * @Author: liyujie
 * @Date: 2021/11/02
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/11/02
-->
<template>
    <section class="wrapper">
        <el-dialog
            title="任务资产充值记录"
            :visible.sync="dialogVisible"
            width="680px"
            :close-on-click-modal="false"
            @close="$emit('close')"
        >
            <div class="dialog-content">
                <el-table
                    :data="logList"
                    style="width: 100%;"
                    max-height="400"
                    class="data-table"
                >
                    <el-table-column
                        prop="content"
                        label="操作内容"
                    />
                    <el-table-column
                        label="操作时间"
                    >
                        <template slot-scope="{row}">
                            {{ row.create_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="dialog-footer">
                <el-button
                    type="primary"
                    size="medium"
                    style="width: 120px;"
                    @click="dialogVisible = false"
                >
                    确定
                </el-button>
            </div>
        </el-dialog>
    </section>
</template>

<script>
import Vue from "vue";

const Dialog = {
    name: "ChargeMoneyLog",
    props: {
        hire_no: {
            type: String,
            default: ''
        }
    },
    data() {
        return {
            dialogVisible: false,
            logList: []
        };
    },
    mounted() {
        this.getLogList();
    },
    methods: {

        /**
         * 显示弹窗
         */
        show() {
            this.dialogVisible = true;
        },

        /**
         * 显示弹窗
         */
        close() {
            this.dialogVisible = false;
        },

        /**
         * 获取数据
         */
        getLogList() {
            let params = {
                type: 2,
                hire_no: this.hire_no
            };

            this.$post('/student/hire_user%5Cget_log_list', params, resp => {
                if (resp.code === 1) {
                    this.logList = resp.data.list;
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        },
    }
};

export default Dialog;

const chargeMoneyLog = function (config) {
    return new Promise((resolve) => {
        const DialogConstructor = Vue.extend(Dialog);
        const instance = new DialogConstructor({
            propsData: config,
        }).$mount();

        instance.$on("close", function () {
            setTimeout(() => {
                document.body.removeChild(instance.$el);
                instance.$destroy();
            }, 300);
            resolve(false);
        });
        instance.$on("confirm", function (data) {
            instance.close();
            resolve(data);
        });
        document.body.appendChild(instance.$el);
        instance.dialogVisible = true;
    });
};

export { chargeMoneyLog };
</script>

<style scoped lang="less">
.wrapper {
    .dialog-content {
        display: flex;
        flex-direction: column;
        padding: 0 32px;
        .data-table {
            ::-webkit-scrollbar {
                width: 6px;
                height: 6px;
            }
        }
    }
    .dialog-footer {
        margin-top: 24px;
        display: flex;
        justify-content: center;
    }
}

/deep/ .el-dialog__header {
    padding-top: 10px;
    box-shadow: 0 1px 0 0 rgba(233, 233, 233, 1);
    display: flex;
    align-items: center;
    background: #FAFAFA;
    border-radius: 4px 4px 0 0;

    .el-dialog__title {
        font-weight: 500;
        color: #333;
        font-size: 14px;
    }

    .el-icon-close:before {
        color: rgb(194, 194, 194);
        font-size: 17px;
        font-weight: bold;
    }

    .el-dialog__headerbtn {
        top: 14px;
    }
}

/deep/ .el-dialog__body {
    padding: 24px 32px;
}

/deep/ .el-textarea__inner {
    resize: none;
}
</style>
